//
//  WPThirdView.m
//  wobingwoyi
//
//  Created by WGP on 16/7/26.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPThirdView.h"

#define HomeBtnWidth (SCREEN_WIDTH / 3)

@interface WPThirdView ()

@end

@implementation WPThirdView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {

        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
//    self.backgroundColor = [UIColor redColor];
    
    UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"chahua"]];
    [self addSubview:bgImageView];
    
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(64*SCALE + 1);
        make.left.right.bottom.equalTo(self);
    }];
    
    WPThirdViewOfBtnView *firstBtnView = [[WPThirdViewOfBtnView alloc] initWith:@"pifubin" title:@"皮肤病" introduceStr:@"远离皮肤病的困扰" type:WPDiseaseTypesFirst block:^(WPDiseaseTypes diseaseType) {
        
        if ([self.delegate respondsToSelector:@selector(WPThirdViewDelegateWith:diseaseType:)]) {
            
            [self.delegate WPThirdViewDelegateWith:self diseaseType:diseaseType];
        }
        
    }];
    [self addSubview:firstBtnView];
    
    WPThirdViewOfBtnView *secondBtnView = [[WPThirdViewOfBtnView alloc] initWith:@"manxinbin" title:@"慢性病" introduceStr:@"健康生活我病我医" type:WPDiseaseTypesSecond block:^(WPDiseaseTypes diseaseType) {
        if ([self.delegate respondsToSelector:@selector(WPThirdViewDelegateWith:diseaseType:)]) {
            
            [self.delegate WPThirdViewDelegateWith:self diseaseType:diseaseType];
        }
    }];
    [self addSubview:secondBtnView];
    
    WPThirdViewOfBtnView *thirdBtnView = [[WPThirdViewOfBtnView alloc] initWith:@"yinanzazheng" title:@"血液病" introduceStr:@"了解并远离血液病" type:WPDiseaseTypesThird block:^(WPDiseaseTypes diseaseType) {
        if ([self.delegate respondsToSelector:@selector(WPThirdViewDelegateWith:diseaseType:)]) {
            
            [self.delegate WPThirdViewDelegateWith:self diseaseType:diseaseType];
        }
    }];
    
    
    
    [self addSubview:thirdBtnView];
    
    WPThirdViewOfBtnView *fourthBtnView = [[WPThirdViewOfBtnView alloc] initWith:@"wuguanke" title:@"肿瘤病" introduceStr:@"科学养生预防肿瘤" type:WPDiseaseTypesFourth block:^(WPDiseaseTypes diseaseType) {
        if ([self.delegate respondsToSelector:@selector(WPThirdViewDelegateWith:diseaseType:)]) {
            
            [self.delegate WPThirdViewDelegateWith:self diseaseType:diseaseType];
        }
    }];
    [self addSubview:fourthBtnView];
    
    WPThirdViewOfBtnView *fivethBtnView = [[WPThirdViewOfBtnView alloc] initWith:@"feipangzheng" title:@"婴幼儿疾病" introduceStr:@"打造精致健康生活" type:WPDiseaseTypesFifth block:^(WPDiseaseTypes diseaseType) {
        if ([self.delegate respondsToSelector:@selector(WPThirdViewDelegateWith:diseaseType:)]) {
            
            [self.delegate WPThirdViewDelegateWith:self diseaseType:diseaseType];
        }
    }];
    [self addSubview:fivethBtnView];
    
    WPThirdViewOfBtnView *sixthBtnView = [[WPThirdViewOfBtnView alloc] initWith:@"gengduojibing" title:@"更多疾病" introduceStr:@"预防疾病了解更多" type:WPDiseaseTypesSixth block:^(WPDiseaseTypes diseaseType) {
        if ([self.delegate respondsToSelector:@selector(WPThirdViewDelegateWith:diseaseType:)]) {
            
            [self.delegate WPThirdViewDelegateWith:self diseaseType:diseaseType];
        }
    }];
    [self addSubview:sixthBtnView];
    
    UIView *firstLine = [self lineView];
    UIView *secondLine = [self lineView];
    UIView *thirdLine = [self lineView];
    
    [firstBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self);
        make.width.mas_equalTo(HomeBtnWidth);
        make.height.mas_equalTo(117*SCALE);
    }];
    
    [secondBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(firstBtnView);
        make.height.width.equalTo(firstBtnView);
        make.left.equalTo(firstBtnView.mas_right);
        
    }];
    
    [thirdBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(secondBtnView.mas_right);
        make.height.width.equalTo(firstBtnView);
        make.top.equalTo(firstBtnView);
    }];
    
    [fourthBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(firstBtnView);
        make.top.equalTo(firstBtnView.mas_bottom);
    }];
    
    [fivethBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(secondBtnView);
        make.top.equalTo(secondBtnView.mas_bottom);
    }];
    
    [sixthBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(thirdBtnView);
        make.top.equalTo(thirdBtnView.mas_bottom);
    }];
    
    [firstLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(0.5);
        make.left.equalTo(self).offset(5);
        make.right.equalTo(self).offset(-5);
        make.top.equalTo(firstBtnView.mas_bottom);
    }];
    
    [secondLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(0.5);
        make.top.equalTo(self).offset(5);
        make.bottom.equalTo(fourthBtnView);
        make.centerX.equalTo(firstBtnView.mas_right);
    }];
    
    [thirdLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.top.bottom.equalTo(secondLine);
        make.centerX.equalTo(secondBtnView.mas_right);
    }];
}

-(UIView *)lineView
{
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = HomeLineColor;
    [self addSubview:lineView];
    return lineView;
}

@end










